package com.j2205.hongzhiyuan.controller;

import com.alibaba.fastjson.JSON;
import com.j2205.hongzhiyuan.pojo.DbBack;
import com.j2205.hongzhiyuan.service.DbBackService;
import com.j2205.hongzhiyuan.service.impl.DbBackServiceImpl;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

/**
 * @ClassName DbBackServlet
 * @Description TODO
 * @Author Zbt
 * @Date 2022/8/18 17:10
 * @Version 1.0
 **/
public class DbBackServlet extends BaseServlet{
    public void findAll(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        DbBackService dbBackService = new DbBackServiceImpl();
        List<DbBack> all = dbBackService.findAll();
        resp.setContentType("application/html;charset=UTF-8");
        String s = JSON.toJSONString(all);
        PrintWriter writer = resp.getWriter();
        writer.write(s);
        writer.flush();
        writer.close();
    }
    public void delete(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        int bkID = Integer.parseInt(req.getParameter("bkID"));
        System.out.println(bkID);
        DbBackService dbBackService = new DbBackServiceImpl();
        boolean b =  dbBackService.delete(bkID);
        resp.setContentType("application/json;charset=UTF-8");
        PrintWriter writer = resp.getWriter();
        if (b){
            writer.write("success");
        }else {
            writer.write("fail");
        }
        writer.flush();
        writer.close();
    }
}
